package com.jzo2o.customer.controller.consumer;

/*
 *   Description AddressBookController
 *   @author zhangyan
 *   @time   2024/12/2
 */

import com.jzo2o.common.model.PageResult;
import com.jzo2o.customer.model.domain.AddressBook;
import com.jzo2o.customer.model.dto.request.AddressBookPageQueryReqDTO;
import com.jzo2o.customer.model.dto.request.AddressBookUpsertReqDTO;
import com.jzo2o.customer.service.IAddressBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("addressBookController")
@RequestMapping("/consumer/address-book")
@Api(tags = "用户端 - 地址簿相关接口")
@Slf4j
public class AddressBookController {
    @Autowired
    private IAddressBookService addressBookService;

    @PostMapping
    @ApiOperation("创建地址")
    public void creat(@RequestBody AddressBookUpsertReqDTO dto) {

        addressBookService.creat(dto);
    }

    @GetMapping("/page")
    @ApiOperation("分页查询地址")
    public PageResult page(AddressBookPageQueryReqDTO dto) {

        return addressBookService.pageQuery(dto);
    }

    @GetMapping("/{id}")
    @ApiOperation("查询地址详情")
    public AddressBook findById(@PathVariable("id") Long id) {
        return addressBookService.getById(id);
    }

    @PutMapping("/{id}")
    @ApiOperation("更新地址")
    public void updatebyId(@RequestBody AddressBookUpsertReqDTO dto, @PathVariable Long id) {
        addressBookService.updatebyId(dto, id);
    }

    @DeleteMapping("/batch")
    @ApiOperation("批量删除地址")
    public void deletebatch(@RequestBody List<String> ids) {
        addressBookService.deletebatch(ids);
    }
    @PutMapping("/default")
    @ApiOperation("设置默认地址")
    public void toDefault(@RequestParam("flag") Integer flag,@RequestParam("id") Long id){
        addressBookService.toDefault(flag,id);
    }

    public AddressBook findDefault() {
        return addressBookService.findDefault();
    }
}
